Skip to content

feat(react): high-contrast syntax highlighting with light/dark pair - #162

Merged
RhysSullivan merged 3 commits into
UsefulSoftwareCo:mainfrom
mrzmyr:ui/syntax-highlighting
Apr 10, 2026
Merged

feat(react): high-contrast syntax highlighting with light/dark pair#162
RhysSullivan merged 3 commits into
UsefulSoftwareCo:mainfrom
mrzmyr:ui/syntax-highlighting

Conversation

@mrzmyr

@mrzmyr mrzmyr commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replaces the single vitesse-dark theme (used in both color schemes) with a GitHub Light/Dark pair.
  • Adds useIsDark and useResolvedShikiTheme hooks so code blocks react to the system color scheme.
  • Exposes a new theme prop on <CodeBlock> and <ExpandableCodeBlock> — callers can pass a single theme or a { light, dark } pair.
  • The Streamdown code-highlighter plugin now keys its cache per active theme, so toggling dark mode does not serve stale tokens.

Changes

  • packages/react/src/lib/shiki.ts
  • packages/react/src/components/code-block.tsx
  • packages/react/src/components/expandable-code-block.tsx

mrzmyr and others added 3 commits April 10, 2026 21:18
The previous single Vitesse Dark theme was the same in both modes
and lacked contrast. Switch to GitHub Light/Dark as the default pair
and make the theme selectable at the component level.

- `lib/shiki.ts`: export `SupportedTheme`, `DEFAULT_LIGHT_THEME`,
  `DEFAULT_DARK_THEME`, and a `ShikiThemeProp` that accepts either a
  single theme or a `{ light, dark }` pair. Add `useIsDark` and
  `useResolvedShikiTheme` hooks so components can react to the
  system color-scheme. Load both GitHub themes up-front.
- `CodeBlock` and `ExpandableCodeBlock`: accept an optional `theme`
  prop and pass it through the tokenization hooks.
- Streamdown plugin: key its cache per active theme so switching
  color schemes doesn't serve stale tokens.
Move useIsDark into its own hook file so it can be reused outside
of syntax highlighting. Also remove unused THEME export and
vitesse-dark theme.
@RhysSullivan
RhysSullivan merged commit 1db298d into UsefulSoftwareCo:main Apr 10, 2026
0 of 4 checks passed
RhysSullivan added a commit that referenced this pull request May 31, 2026
…162)

* feat(react): high-contrast syntax highlighting with light/dark pair

The previous single Vitesse Dark theme was the same in both modes
and lacked contrast. Switch to GitHub Light/Dark as the default pair
and make the theme selectable at the component level.

- `lib/shiki.ts`: export `SupportedTheme`, `DEFAULT_LIGHT_THEME`,
  `DEFAULT_DARK_THEME`, and a `ShikiThemeProp` that accepts either a
  single theme or a `{ light, dark }` pair. Add `useIsDark` and
  `useResolvedShikiTheme` hooks so components can react to the
  system color-scheme. Load both GitHub themes up-front.
- `CodeBlock` and `ExpandableCodeBlock`: accept an optional `theme`
  prop and pass it through the tokenization hooks.
- Streamdown plugin: key its cache per active theme so switching
  color schemes doesn't serve stale tokens.

* refactor(react): extract useIsDark hook from shiki module

Move useIsDark into its own hook file so it can be reused outside
of syntax highlighting. Also remove unused THEME export and
vitesse-dark theme.

---------

Co-authored-by: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants